package com.ruoyi.project.express.accounts.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.express.accounts.domain.ExpressAccounts;
import com.ruoyi.project.express.accounts.service.IExpressAccountsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 物流账号Controller
 * 
 * @author lindor
 * @date 2020-04-07
 */
@Controller
@RequestMapping("/express/accounts")
public class ExpressAccountsController extends BaseController
{
    private String prefix = "express/accounts";

    @Autowired
    private IExpressAccountsService expressAccountsService;

    @RequiresPermissions("express:accounts:view")
    @GetMapping()
    public String accounts()
    {
        return prefix + "/accounts";
    }

    /**
     * 查询物流账号列表
     */
    @RequiresPermissions("express:accounts:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExpressAccounts expressAccounts)
    {
        startPage();
        List<ExpressAccounts> list = expressAccountsService.selectExpressAccountsList(expressAccounts);
        return getDataTable(list);
    }

    /**
     * 导出物流账号列表
     */
    @RequiresPermissions("express:accounts:export")
    @Log(title = "物流账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExpressAccounts expressAccounts)
    {
        List<ExpressAccounts> list = expressAccountsService.selectExpressAccountsList(expressAccounts);
        ExcelUtil<ExpressAccounts> util = new ExcelUtil<ExpressAccounts>(ExpressAccounts.class);
        return util.exportExcel(list, "accounts");
    }

    /**
     * 新增物流账号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物流账号
     */
    @RequiresPermissions("express:accounts:add")
    @Log(title = "物流账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExpressAccounts expressAccounts)
    {
        return toAjax(expressAccountsService.insertExpressAccounts(expressAccounts));
    }

    /**
     * 修改物流账号
     */
    @GetMapping("/edit/{partnerId}")
    public String edit(@PathVariable("partnerId") Long partnerId, ModelMap mmap)
    {
        ExpressAccounts expressAccounts = expressAccountsService.selectExpressAccountsById(partnerId);
        mmap.put("expressAccounts", expressAccounts);
        return prefix + "/edit";
    }

    /**
     * 修改保存物流账号
     */
    @RequiresPermissions("express:accounts:edit")
    @Log(title = "物流账号", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExpressAccounts expressAccounts)
    {
        return toAjax(expressAccountsService.updateExpressAccounts(expressAccounts));
    }

    /**
     * 删除物流账号
     */
    @RequiresPermissions("express:accounts:remove")
    @Log(title = "物流账号", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(expressAccountsService.deleteExpressAccountsByIds(ids));
    }
}
